let https = require('https');
let cheerio = require('cheerio');
let aa;
aa = '/result?word=lj%3Amerges%20in%20to&lang=en';
aa = '/result?word=lj%3Amerge%20in&lang=en';
aa = '/result?word=lj%3Amerge&lang=en';
aa = '/result?word=lj%3Amerges&lang=en';

const options = {
    hostname: 'dict.youdao.com',
    port: 443,
    path: '/result?word=lj%3Amerging&lang=en',
    method: 'GET',
    headers : {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
    }
};

function cheerioIt(html) {
    // cheerio.load(html,{xmlMode: true, decodeEntities: false});
    let $cheerioed = cheerio.load(html,{xmlMode: false});
    let sentences = $cheerioed('#catalogue_sentence');

    let lis = sentences.find(".dict-book .trans-container>ul>li");
    lis.each(function (idx, theLi){
        console.log($cheerioed(theLi).find('.sen-eng').text());
        console.log($cheerioed(theLi).find('.sen-ch').text());

    })
    console.log("");

}

const req = https.request(options, (res) => {
    let html = '';
});

// const req = https.request(options, (res) => {
//     // console.log('statusCode:', res.statusCode);
//     // console.log('headers:', res.headers);
//
//     let html = '';
//     res.on('data', (chunk) => {
//         html+=chunk;
//     });
//
//     res.on('end', (chunk) => {
//         cheerioIt(html);
//     });
// });

req.on('error', (e) => {
    console.error(e);
});
req.end();